function refreshvcode() {
	$('#page-login-vcode-img').attr('src',
			'get_verification_code?i=' + Math.random());
}
$(document).ready(function() {
	$('#page-login-vcode-img').bind('click', refreshvcode);
	$('#send-mail-vcode').bind('click', function() {
		$("#login-info").fadeOut();
		$('#send-mail-vcode').attr("disabled", true);
		$.post('ajax_send_mail_vcode', {
			'mail' : $('#mail').val()
		}, function(data, status) {
			if (status == 'success') {
				$("#login-info").fadeIn();
				$("#login-info").text(data.msg);
				$('#send-mail-vcode').attr("disabled", false);
			} else {
				$("#login-info").fadeIn();
				$("#login-info").text("网络错误");
				$('#send-mail-vcode').attr("disabled", false);
			}
		});
	});
	$('#register').bind('click', function() {
		$("#login-info").fadeOut();
		$('#register').attr("disabled", true);
		$.post('ajax_register', {
			'name' : $('#name').val(),
			'mail' : $('#mail').val(),
			'password' : $('#password').val(),
			'mail_vcode' : $('#mail_vcode').val(),
			'vcode' : $('#vcode').val()
		}, function(data, status) {
			if (status == 'success') {
				if (data.type == 0) {
					location.href = "Login";
				} else {
					$("#login-info").fadeIn();
					$("#login-info").text(data.msg);
					$('#register').attr("disabled", false);
					refreshvcode();
				}
			} else {
				$("#login-info").fadeIn();
				$("#login-info").text("网络错误");
				$('#register').attr("disabled", false);
				refreshvcode();
			}
		});
	});
});